﻿<%@ Page Title="" Language="C#" MasterPageFile="~/ConfExpert.master" AutoEventWireup="true"
    CodeFile="Du4Missing.aspx.cs" Inherits="Du4Missing" %>

<asp:Content ID="content" ContentPlaceHolderID="phMain" runat="Server">
    <script type="text/javascript">
        var _fieldName = '';

        function OnRowDblClick(s, e) {
            var srcElement = e.htmlEvent.srcElement;
            _fieldName = srcElement.getAttribute('FieldName');
            s.StartEditRow(e.visibleIndex);
        }

        function showDetail() {
            popupClick = true;

            var content = $("#MissingDetail")[0].innerHTML;
            var htm = $(content);

            $.lightbox(htm, {
                width: 1200,
                height: 250
            });

            return false;
        }
        function doCallBack(id) {
            grdMissingDetail.PerformCallback(id);
        }


    </script>
    <dx:ASPxGridViewExporter ID="gve" runat="server">
    </dx:ASPxGridViewExporter>
    <asp:SqlDataSource ID="sds" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ce %>" 
        SelectCommand="select * from ( SELECT *,(select top 1 MissingQty from Du4MissingLines where Du4MissingId = d.Du4MissingId order by Du4MissingLinesId desc) MissingQty  ,(select top 1 Notes MissingQty from Du4MissingLines where Du4MissingId = d.Du4MissingId order by 1 desc) LastNote FROM [Du4Missing] d )s where MissingQty > 0" 
        DeleteCommand="DELETE FROM [Du4Missing] WHERE [Du4MissingId] = @Du4MissingId" 
        InsertCommand="INSERT INTO [Du4Missing] ([ProductId], [Product], [CustomerCode], [Composition], [ModifiedOn]) VALUES (@ProductId, @Product, @CustomerCode, @Composition, @ModifiedOn)" 
        UpdateCommand="UPDATE [Du4Missing] SET [ProductId] = @ProductId, [Product] = @Product, [CustomerCode] = @CustomerCode, [Composition] = @Composition, [ModifiedOn] = @ModifiedOn WHERE [Du4MissingId] = @Du4MissingId">
        <DeleteParameters>
            <asp:Parameter Name="Du4MissingId" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="ProductId" Type="Int32" />
            <asp:Parameter Name="Product" Type="String" />
            <asp:Parameter Name="CustomerCode" Type="String" />
            <asp:Parameter Name="Composition" Type="String" />
            <asp:Parameter Name="ModifiedOn" Type="DateTime" />
        </InsertParameters>
        <UpdateParameters>
            <asp:Parameter Name="ProductId" Type="Int32" />
            <asp:Parameter Name="Product" Type="String" />
            <asp:Parameter Name="CustomerCode" Type="String" />
            <asp:Parameter Name="Composition" Type="String" />
            <asp:Parameter Name="ModifiedOn" Type="DateTime" />
            <asp:Parameter Name="Du4MissingId" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <asp:SqlDataSource ID="sdsDetail" runat="server" 
        ConnectionString="<%$ ConnectionStrings:ce %>" 
        SelectCommand="SELECT * FROM [Du4MissingLines] WHERE ([Du4MissingId] = @Du4MissingId)" 
        DeleteCommand="DELETE FROM [Du4MissingLines] WHERE [Du4MissingLinesId] = @Du4MissingLinesId" 
        InsertCommand="INSERT INTO [Du4MissingLines] ([Du4MissingId], [MissingQty], [InvoiceNr], [InvoiceDate], [ETD], [Notes], [ModifiedOn]) VALUES (@Du4MissingId, @MissingQty, @InvoiceNr, @InvoiceDate, @ETD, @Notes, @ModifiedOn)" 
        
        UpdateCommand="UPDATE [Du4MissingLines] SET [Du4MissingId] = @Du4MissingId, [MissingQty] = @MissingQty, [InvoiceNr] = @InvoiceNr, [InvoiceDate] = @InvoiceDate, [ETD] = @ETD, [Notes] = @Notes, [ModifiedOn] = @ModifiedOn WHERE [Du4MissingLinesId] = @Du4MissingLinesId">
        <DeleteParameters>
            <asp:Parameter Name="Du4MissingLinesId" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="Du4MissingId" Type="Int32" />
            <asp:Parameter Name="MissingQty" Type="Decimal" />
            <asp:Parameter Name="InvoiceNr" Type="String" />
            <asp:Parameter Name="InvoiceDate" Type="DateTime" />
            <asp:Parameter Name="ETD" Type="DateTime" />
            <asp:Parameter Name="Notes" Type="String" />
            <asp:Parameter Name="ModifiedOn" Type="DateTime" />
        </InsertParameters>
        <SelectParameters>
            <asp:SessionParameter Name="Du4MissingId" SessionField="Du4MissingId" 
                Type="Int32" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="Du4MissingId" Type="Int32" />
            <asp:Parameter Name="MissingQty" Type="Decimal" />
            <asp:Parameter Name="InvoiceNr" Type="String" />
            <asp:Parameter Name="InvoiceDate" Type="DateTime" />
            <asp:Parameter Name="ETD" Type="DateTime" />
            <asp:Parameter Name="Notes" Type="String" />
            <asp:Parameter Name="ModifiedOn" Type="DateTime" />
            <asp:Parameter Name="Du4MissingLinesId" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
    <div id="MissingDetail" style="display: none; width: 100%;">
        <dx:ASPxGridView ID="grdMissingDetail" runat="server" AutoGenerateColumns="True"
            ClientIDMode="AutoID" ClientInstanceName="grdMissingDetail" KeyFieldName="Du4MissingId"
            OnCustomCallback="grdMissingDetail_OnCustomCallback" Width="100%">
            <ClientSideEvents EndCallback="function(s,e){showDetail(s,e);}"></ClientSideEvents>
            <SettingsBehavior AllowDragDrop="False" AllowGroup="False" AllowSort="False" />
            <SettingsBehavior AllowDragDrop="False" AllowSort="False" AllowGroup="False"></SettingsBehavior>
            <SettingsPager Mode="ShowAllRecords">
            </SettingsPager>
            <Settings ShowVerticalScrollBar="True" />
            <Settings ShowVerticalScrollBar="True"></Settings>
            <Styles>
                <Header HorizontalAlign="Center" Wrap="True">
                </Header>
            </Styles>
        </dx:ASPxGridView>
    </div>
    <table>
        <tr>
            <td>
                <dx:ASPxLabel ID="ASPxLabel1" runat="server" ForeColor="red" Font-Italic="true" Text=" Please click the Edit link or double click on the line which you'd like to edit."
                    Wrap="False">
                </dx:ASPxLabel>
            </td>
            <td align="right">
                &nbsp;</td>
        </tr>
        <tr>
            <td>
                &nbsp;
            </td>
            <td align="right">
                &nbsp;
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <dx:ASPxGridView ID="gv" runat="server" Width="900px" KeyFieldName="Du4MissingId"
                    Settings-ShowFilterRow="true" Styles-Header-HorizontalAlign="Center" AutoGenerateColumns="False"
                    Settings-ShowGroupFooter="VisibleAlways" DataSourceID="sds">
                    <ClientSideEvents RowDblClick="OnRowDblClick" />
                    <SettingsText CommandUpdate="Save" />
                    <SettingsDetail ShowDetailRow="True" />
                    <Images>
                        <DetailCollapsedButton ToolTip="To see details please click." 
                            Url="~/Images/plus_small.png">
                        </DetailCollapsedButton>
                        <DetailExpandedButton Url="~/Images/minus_small.png">
                        </DetailExpandedButton>
                    </Images>
                    <Styles>
                        <Header HorizontalAlign="Center" Wrap="True">
                        </Header>
                        <Footer Wrap="False">
                        </Footer>
                    </Styles>
                    <TotalSummary>
                        <dx:ASPxSummaryItem DisplayFormat="∑ {0:n1}" FieldName="MissingQty" ShowInColumn="MissingQty"
                            SummaryType="Sum" ValueDisplayFormat="s{v}" />
                    </TotalSummary>
                    <Columns>
                        <dx:GridViewCommandColumn VisibleIndex="0">
                            <EditButton Visible="True">
                            </EditButton>
                        </dx:GridViewCommandColumn>
                        <dx:GridViewDataTextColumn FieldName="Du4MissingId" ReadOnly="True" Caption="Id"
                            VisibleIndex="1" Width="20px">
                            <EditFormSettings Visible="False" />
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn FieldName="ProductId" Caption="Scan" VisibleIndex="2"
                            Width="20px">
                            <EditFormSettings Visible="False" />
                        </dx:GridViewDataTextColumn>
                        <dx:GridViewDataTextColumn FieldName="Product" VisibleIndex="3">
                            <EditFormSettings Visible="False" />
                        </dx:GridViewDataTextColumn>                        
                 
                        <dx:GridViewDataTextColumn FieldName="CustomerCode" VisibleIndex="4">
                            <EditFormSettings Visible="False" />
                            </dx:GridViewDataTextColumn>

                            <dx:GridViewDataTextColumn FieldName="Composition" VisibleIndex="5">
                            <EditFormSettings VisibleIndex="0" />
                        </dx:GridViewDataTextColumn>

                        <dx:GridViewDataTextColumn FieldName="LastNote" VisibleIndex="6">
                            <EditFormSettings Visible="False"/>
                        </dx:GridViewDataTextColumn>

                        <dx:GridViewDataTextColumn FieldName="MissingQty" VisibleIndex="7">
                            <EditFormSettings Visible="False"/>
                        </dx:GridViewDataTextColumn>

                   
                    </Columns>
                    <SettingsPager Mode="ShowAllRecords">
                    </SettingsPager>
                    <Settings ShowFilterRow="True" ShowFooter="True"></Settings>
                    <Templates>
                        <DetailRow>
                            <dx:ASPxGridView ID="gvDetail" runat="server" AutoGenerateColumns="False" 
                                DataSourceID="sdsDetail" KeyFieldName="Du4MissingLinesId" 
                                onbeforeperformdataselect="gvDetail_BeforePerformDataSelect" 
                                Settings-ShowFilterRow="true" Settings-ShowGroupFooter="VisibleAlways" 
                                Styles-Header-HorizontalAlign="Center" Width="900px">
                                <ClientSideEvents RowDblClick="OnRowDblClick" />
                                <SettingsText CommandUpdate="Save" />
                                <Styles>
                                    <Header HorizontalAlign="Center" Wrap="True">
                                    </Header>
                                    <Footer Wrap="False">
                                    </Footer>
                                </Styles>
                                <TotalSummary>
                                    <dx:ASPxSummaryItem DisplayFormat="∑ {0:n1}" FieldName="MissingQty" 
                                        ShowInColumn="MissingQty" SummaryType="Sum" ValueDisplayFormat="s{v}" />
                                </TotalSummary>
                                <Columns>
                                    <dx:GridViewCommandColumn VisibleIndex="0">
                                        <EditButton Visible="True">
                                        </EditButton>
                                    </dx:GridViewCommandColumn>
                                    <dx:GridViewDataTextColumn Caption="Date" FieldName="ModifiedOn"  CellStyle-Wrap="False"
                                        ReadOnly="True" VisibleIndex="1" Width="20px">
                                        <EditFormSettings Visible="False" />
                                    </dx:GridViewDataTextColumn>
                                    
                                    <dx:GridViewDataTextColumn FieldName="MissingQty" 
                                        PropertiesTextEdit-DisplayFormatString="n1" VisibleIndex="5">
                                        <EditFormSettings Visible="False" />
                                    </dx:GridViewDataTextColumn>
                                    
                                    <dx:GridViewDataTextColumn FieldName="InvoiceNr" VisibleIndex="8">
                                        <EditFormSettings VisibleIndex="2" />
                                    </dx:GridViewDataTextColumn>
                                    <dx:GridViewDataDateColumn FieldName="InvoiceDate" VisibleIndex="9">
                                        <EditFormSettings VisibleIndex="1" />
                                    </dx:GridViewDataDateColumn>
                                    <dx:GridViewDataDateColumn FieldName="ETD" VisibleIndex="10">
                                        <EditFormSettings VisibleIndex="3" />
                                    </dx:GridViewDataDateColumn>
                                    <dx:GridViewDataTextColumn FieldName="Notes" VisibleIndex="11">
                                        <EditFormSettings CaptionLocation="Near" RowSpan="2" VisibleIndex="4" />
                                        <EditItemTemplate>
                                            <dx:ASPxMemo ID="meNotes0" runat="server" Height="50" 
                                                Text='<%# Bind("Notes") %>' Width="375">
                                            </dx:ASPxMemo>
                                        </EditItemTemplate>
                                    </dx:GridViewDataTextColumn>
                                </Columns>
                                <SettingsPager Mode="ShowAllRecords">
                                </SettingsPager>
                                <Settings ShowFilterRow="True" ShowFooter="True" />
                            </dx:ASPxGridView>
                        </DetailRow>
                    </Templates>
                </dx:ASPxGridView>
            </td>
        </tr>
    </table>
    <dx:ASPxPopupControl ID="popBigPhoto" runat="server" ClientInstanceName="popBigPhoto"
        PopupHorizontalAlign="OutsideRight" PopupVerticalAlign="WindowCenter" ClientIDMode="AutoID"
        AppearAfter="1" EnableAnimation="true" ShowHeader="false">
        <ContentStyle VerticalAlign="Middle" HorizontalAlign="Center">
        </ContentStyle>
        <ContentCollection>
            <dx:PopupControlContentControl ID="PopupControlContentControl1" runat="server">
                <dx:ASPxImage ID="ASPxImage1" runat="server" ClientInstanceName="imgBigPopup">
                </dx:ASPxImage>
            </dx:PopupControlContentControl>
        </ContentCollection>
    </dx:ASPxPopupControl>
</asp:Content>
